package com.briup.mt.service.impl;

import com.briup.mt.bean.Interfaces;
import com.briup.mt.bean.InterfacesExample;
import com.briup.mt.dao.InterfacesMapper;
import com.briup.mt.service.IInterfacesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class InterfacesServiceImpl implements IInterfacesService {

    @Autowired
    private InterfacesMapper interfacesMapper;

    @Override
    public List<Interfaces> query(String name, String status) {
        InterfacesExample example = new InterfacesExample();
        if (!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }
        if (!StringUtils.isEmpty(status)){
            example.createCriteria().andStatusEqualTo(status);
        }
        List<Interfaces> list = interfacesMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Interfaces interfacs) {
        if (interfacs.getId()==null){
            interfacesMapper.insert(interfacs);
        }else {
            interfacesMapper.updateByPrimaryKey(interfacs);
        }

    }

    @Override
    public void deleteById(long id) {
        interfacesMapper.deleteByPrimaryKey(id);

    }
}
